package com.mq.config;

import com.mq.autoconfiguration.RedisMqProperties;
import com.mq.core.RedisListenerAnnotationBeanPostProcessor;
import com.mq.core.factory.RedisListenerContainerFactory;
import com.mq.core.factory.SimpleRedisListenerContainerFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Role;

import javax.annotation.Resource;

@Configuration
public class RedisMqFactoryConfig {

    @Resource
    private RedisMqProperties redisMqProperties;

    @Bean(name = "RedisListenerAnnotationBeanPostProcessor")
    @Role(BeanDefinition.ROLE_INFRASTRUCTURE)
    public RedisListenerAnnotationBeanPostProcessor rabbitListenerAnnotationProcessor() {
        return new RedisListenerAnnotationBeanPostProcessor();
    }


    @Bean
    public RedisListenerContainerFactory redisListenerContainerFactory(){
        SimpleRedisListenerContainerFactory factory
                = new SimpleRedisListenerContainerFactory();
        factory.setMaxConsumer(redisMqProperties.getMaxConsumer());
        factory.setRetryTimes(redisMqProperties.getRetryTimes());
        return factory;
    }
}
